package com.thh.project.controller;

import com.thh.project.common.exception.CommonException;
import com.thh.project.common.exception.ExceptionCast;
import com.thh.project.model.common.dtos.ResponseResult;
import com.thh.project.model.common.enums.AppHttpCodeEnum;
import com.thh.project.model.user.pojos.ApUser;
import com.thh.project.service.ApUserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/login")
public class LoginController {

    @Autowired
    private ApUserLoginService apUserLoginService;

    @PostMapping("/login_auth")
    public ResponseResult login(@RequestBody @Valid ApUser user) {
        ExceptionCast.castCommonException(AppHttpCodeEnum.TOKEN_INVALID);
        return apUserLoginService.loginAuth(user);
    }

}
